package com.huluobo.a2308douyindemo.demo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.huluobo.a2308douyindemo.R
import com.huluobo.a2308douyindemo.databinding.ActivityDataBindingBinding

class DataBindingActivity : AppCompatActivity() {
    private lateinit var binding: ActivityDataBindingBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityDataBindingBinding.inflate(layoutInflater)
        setContentView(binding.root)

        binding.btn.setOnClickListener {
            val username = binding.username.text.toString()
            val password = binding.password.text.toString()
            val age = binding.age.text.toString()
            val desc = binding.desc.text.toString()

            //生成user对象
            val userBean = UserBean(
                username,
                password,
                age.toInt(),
                desc,
                "https://c-ssl.dtstatic.com/uploads/blog/202303/03/20230303143138_e62cb.thumb.1000_0.jpg"
            )
            //给xml上的user赋值
            binding.user = userBean
        }
    }
}